<?php
function my_header($title)
{
    ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html><head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title><?php echo $title; ?></title>
        <link href="css/gemeCSS.css" rel="stylesheet" type="text/css"  media="screen" />
        <script type="text/javascript" src="js/jquery-1.7.min.js" ></script>
        <script type="text/javascript" src="js/bp.js" ></script>
        <script type="text/javascript" src="js/script.js" ></script>
		<link rel="shortcut icon" href="img/fav.png" type="image/x-png" />
    </head><body>
    <?php
}

/* function my_header2($title)
 {
   ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html><head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
         <title><?php echo $title; ?></title>
        <link href="css/gemeCSS.css" rel="stylesheet" type="text/css"  media="screen" />
         <script type="text/javascript" src="js/jquery-1.7.min.js" ></script>
         <script type="text/javascript" src="js/bp.js" ></script>
         <script type="text/javascript" src="js/script.js" ></script>
         <link href="avatar/uploadify.css" type="text/css" rel="stylesheet" />
         </script>
     </head><body>
     <?php
} */

function db(){
    mysql_connect('localhost','root','') or die('Mysql connect error'); 
    mysql_select_db('jwak') or die('Database select error');
    mysql_query('SET NAMES UTF8');
}

function footer(){
    ?>
        <br />
    <div class="footer">
                    © JwakK.com · Всички права запазени · <a href="#">Условия за ползване</a>
                </div>
    <?php
}

function thumb($src)
{
	if($src['type']=="image/jpeg")
		{
			  $source_image = imagecreatefromjpeg($src['tmp_name']);  
		}
	elseif($src['type']=="image/png")
		{
			  $source_image = imagecreatefrompng($src['tmp_name']);
		}
	elseif($src['type']=="image/gif")
		{
			  $source_image = imagecreatefromgif($src['tmp_name']);
			  
		}



  $width = imagesx($source_image);
  $height = imagesy($source_image);
  $desired_height = "142" ;
  $desired_width =  floor($width*($desired_height/$height));
  $virtual_image = imagecreatetruecolor($desired_width,$desired_height);
  imagecopyresized($virtual_image,$source_image,0,0,0,0,$desired_width,$desired_height,$width,$height);
  // imagejpeg($virtual_image,$dest);
	$hash = md5($src['name'].$_SERVER['REMOTE_ADDR'].time().$_SESSION['user_info']['user']) ; 
	$name = "img/avatars/".$hash ; 
	if($src['type']=="image/jpeg")
		{
			imagepng($virtual_image,$name.".jpg") ; 
			mysql_query('UPDATE users SET avatar="'.$name.'.jpg" WHERE user  = "'.$_SESSION['user_info']['user'].'"') ; 
		}
	elseif($src['type']=="image/png")
		{
			  imagepng($virtual_image,$name.".png") ; 
			  mysql_query('UPDATE users SET avatar="'.$name.'.png" WHERE user  = "'.$_SESSION['user_info']['user'].'"') ; 
		}
	elseif($src['type']=="image/gif")
		{
			 imagegif($virtual_image,$name.".gif");
			 mysql_query('UPDATE users SET avatar="'.$name.'.gif" WHERE user  = "'.$_SESSION['user_info']['user'].'"') ; 
			
		}
		
}

